{extend name="./app/admin/view/main.html" /}

{block name="title"}内容智能迁入 - {__block__}{/block}

{block name="style"}
{__block__}

<style type="text/css">
         
    .sortable-chosen {
        background-color: #d9effd;
    }
    .sortable-ghost {
        background-color: #eef2f6;
    }
</style>

{/block}
{block name="main"}
<header class="nicemip-container-header">
    <div class="float-left">
        <h4>内容智能迁入</h4>
    </div>
   <button type="button" class="pull-right ivu-btn ivu-btn-primary ivu-btn-circle" @click='itemAdd'>
        <span><Icon type="plus-round"></Icon> 添加</span>
    </button>
</header>

<main class="nicemip-container-body" style="height: calc(100% - 50px)">
    <section class="nice-box">
        <div class="nice-box-body">
                <section class="diy-table-list" v-if='itemList.length > 0'>
                    <div class="diy-table-item diy-table-item-header">
                        <div class="list-unstyled row">
                            <div class="col-md-2">内容分类</div>
                            <div class="col-md-4">内容来源列表地址</div>
                            <div class="col-md-1">同步内容</div>
                            <div class="col-md-2">最近同步时间</div>
                            <div class="col-md-1">同步状态</div>
                            <div class="col-md-2">操作</div>
                        </div>
                    </div>
                <draggable :list="itemList">
                    <div class="diy-table-item" v-for='item in itemList' >
                            <div class="list-unstyled row">
                                <div class="col-md-2">{{item.name}}</div>
                                <div class="col-md-4 text-overflow">{{item.url}}</div>
                                <div class="col-md-1">{{item.exe_suc_count}} 次</div>
                                <div class="col-md-2">
                                    <span v-if="item.exe_end_time">{{item.exe_end_time | time}}</span>
                                    <span style="color:gray" v-else>--</span>
                                </div>
                                <div class="col-md-1">
                                    <span style="color:green" v-if='item.exe_status == "doing"'>执行中</span>
                                    <span style="color:red" v-else-if='item.exe_status == "fail"'>执行失败</span>
                                    <span style="color:orange;" v-else-if='item.exe_status == "timeout"'>执行超时</span>
                                    <span style="color:gray" v-else-if='item.exe_end_time != 0'>执行完成</span>
                                    <span style="color:gray" v-else>未执行</span>
                                </div>
                                <div class="col-md-2 text-right p-r-md">
                                    <i-button type="error" size="small" @click='itemDel(item)'>删除</i-button>
                                    <i-button type="primary" size="small" @click='itemExe(item)'>执行</i-button>
                                </div>
                          </div>
                    </div>
                </draggable>
                </section>
                <div class="no-block" v-else>
                    <Icon type="ios-filing-outline"></Icon>
                    <p>暂无数据</p>
                </div>
                    
            </div>
    </section>
</main>
</div>
{/block}
{block name="javascript"}
{__block__}
<script>
    new Vue({
        el: '#app',
        data:{

            itemList: [],
        },
        mounted: function() {
            _this = this;
            this.getItemList();
        },
        methods:{
            itemAdd: function() {
                window.location.href = '{$domain}/{$Think.config.admin}/addons/autocontentincome/AdminAutoContentIncome/autoContentIncomeStep';
            },
            itemDel: function(val) {
               this.$Modal.confirm({
                    title: '消息提示',
                    content: '<p>确定删除么？删除后不可恢复</p>',
                    onOk: () => {
                        this.$nicemip.ajax('{$domain}/{$Think.config.admin}/ApiAdminACI/autoContentIncomeDel',{
                            id: val.id,
                        }).then(function (res) {
                            if (res.code == 1) {
                                _this.$Message.success(res.msg);
                                _this.getItemList();
                            }
                        });
                    },
                    onCancel: () => {
                    }
                });
            },
            itemExe: function(val) {
                this.$nicemip.ajax('{$domain}/{$Think.config.admin}/ApiAdminACI/autoContentIncomeExe',{
                    id: val.id,
                }).then(function (res) {
                    if (res.code == 1) {
                        _this.$Message.success(res.msg);
                        _this.getItemList();
                    }
                });
            },
            getItemList: function() {
                this.$nicemip.ajax('{$domain}/{$Think.config.admin}/ApiAdminACI/autoContentIncomeSelect',{
                    order: 'asc',
                }).then(function (res) {
                    if (res.code == 1) {
                        var itemList = res.data.autoContentIncomeList;
                        if (itemList.length == 0) {
                            window.location.href = '{$domain}/{$Think.config.admin}/addons/autocontentincome/AdminAutoContentIncome/autoContentIncomeStep';
                        }
                        _this.itemList = itemList;
                    }
                });
            },
        },

    })
</script>
{/block}